package com.interpreter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class ClientTest {

    public static void main(String[] args) throws IOException {
        String expStr = getExpStr(); // a+b
        HashMap<String, Integer> var = getValue(expStr); // {a=10, b=20}
        String expStr1 = getExpStr(); // a+b
        Calculator calculator = new Calculator(expStr1);
        System.out.println("运算结果：" + expStr + "=" + calculator.run(var));
    }

    private static HashMap<String, Integer> getValue(String expStr) {
        HashMap<String, Integer> map = new HashMap<>();
        int time=0;
        for (char ch:expStr.toCharArray()){
            if(ch != '+' && ch != '-'){
                time++;
                if(time>1){
                    map.put("a",ch-48);
                }else {
                    map.put("b",ch-48);
                }
            }
        }
        return map;
    }

    private static String getExpStr() throws IOException {
        System.out.println("请输入表达式：");
        return (new BufferedReader(new InputStreamReader(System.in))).readLine();
    }
}
